public class myQueue1 {
    //用双向链表实现队列(头插尾删)不带头结点不循环
    static class linkList{
        public int val;
        public linkList prev;
        public linkList next;
        public linkList(int val){
            this.val=val;
        }
    }
    public linkList head;
    //入栈
    public void offer(int val){
        linkList node=new linkList(val);
        if(empty()){
            head=node;
        }else{
            node.next=head;
            head.prev=node;
            head=node;
        }
    }
    //出栈
    public int poll(){
        int value=0;
        if(empty()){
            return -1;
        }else {
            if(head.next==null){
                value=head.val;
                head=null;
            }else {
                linkList pcur = head;
                while (pcur.next != null) {
                    pcur = pcur.next;
                }
                value=pcur.val;
                pcur.prev.next=null;

            }
        }
        return value;
    }
    //取栈顶元素
    public int peek(){
        int value=0;
        if(empty()){
            return -1;
        }else{
            linkList pcur = head;
            while (pcur.next != null) {
                pcur = pcur.next;
            }
            value=pcur.val;
        }
        return value;
    }
    //判空
    public boolean empty(){
        return head==null;
    }
}
